package com.zhl.controller;

import com.alibaba.fastjson.JSON;
import com.zhl.entity.INSBMessage;
import com.zhl.entity.User;
import com.zhl.service.UserService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/4/12.
 * 测试mybatis多数据源
 *
 */
@RestController
public class UserController {

    //zhagnlei666修改代码


    @Resource
    private UserService userService;

    @RequestMapping("/index")
    public String getIndex() throws Exception {
        return "index";
    }


    @RequestMapping("/getuser/{id}")
    @ResponseBody
    public String getUser(@PathVariable String id) throws Exception {

        User user = userService.getUser(id);
        System.out.println(JSON.toJSONString(user));
        return JSON.toJSONString(user);

    }

    @RequestMapping("/getusers")
    public String getUsers() throws Exception {

        List<User> users = userService.getUser();
        System.out.println(JSON.toJSONString(users));
        return "";

    }

    @RequestMapping("/getmessage")
    @ResponseBody
    public String getMessages() throws Exception {
        List<INSBMessage> messages = userService.getMessages();
        System.out.println(JSON.toJSONString(messages));
        return JSON.toJSONString(messages);
    }
}
